
#include <BRender>
#include <BState>
#include <BMaterial>
#include <BSphere>
#include "member_BSphere.h"

using namespace BWE;

#define member					(*(member_BSphere*)_ptr)
#define member_allocate()		_ptr = new member_BSphere(this)
#define member_release()		delete (member_BSphere*)_ptr

BSphere::BSphere()
{
	member_allocate();
}
BSphere::BSphere(float radius)
{
	member_allocate();
	this->setRadius(radius);
}
BSphere::BSphere(float radius, int sides, int segments)
{
	member_allocate();
	this->setRadius(radius);
	this->setSides(sides);
	this->setSegments(segments);
}
BSphere::~BSphere()
{
	member_release();
}

void BSphere::setRadius(float radius)
{
	if (member.radius != radius)
	{
		member.radius = radius;
		this->dirty();
	}
}
float BSphere::radius() const
{
	return member.radius;
}

void BSphere::setSides(int sides)
{
	if (member.sides != sides)
	{
		member.sides = sides;
		member.prepare();
		this->dirty();
	}
}
int BSphere::sides() const
{
	return member.sides;
}

void BSphere::setSegments(int segments)
{
	if (member.segments != segments)
	{
		member.segments = segments;
		this->dirty();
	}
}
int BSphere::segments() const
{
	return member.segments;
}

void BSphere::refresh()
{
	BSpace space;
	space.min() = BVector(-member.radius, -member.radius, -member.radius);
	space.max() = BVector(member.radius, member.radius, member.radius);
	this->setSpace(space);
	member.rebuild();
}
void BSphere::render(BRender& render)
{
	BGeometry::render(render);
	//BVectorArray* vertices = this->vertices();
	//BVectorArray* normals = this->normals();
	//render.setColor(255, 0, 0);
	//render.setPointSize(6);
	//render.drawPoints(*vertices);
	//
	//render.setDepthTest(false);
	//render.setColor(0, 255, 0);
	//render.drawPoint((*vertices)[1]);
	//render.setColor(0, 0, 255);
	//render.drawPoint((*vertices)[2]);
}
